#include <iostream>
#include <string>
#include <cmath>

std::string multiply(const std::string& num1, const std::string& num2) {
    if (num1 == "0" || num2 == "0") {
        return "0";
    }

    std::string product(num1.size() + num2.size(), '0');
    for (int i = num1.size() - 1; i >= 0; --i) {
        int carry = 0;
        for (int j = num2.size() - 1; j >= 0; --j) {
            int sum = (num1[i] - '0') * (num2[j] - '0') + (product[i + j + 1] - '0') + carry;
            carry = sum / 10;
            product[i + j + 1] = sum % 10 + '0';
        }
        product[i] += carry;
    }

    size_t startpos = product.find_first_not_of("0");
    if (startpos != std::string::npos) {
        return product.substr(startpos);
    }
    return "0";
}

std::string power(const std::string& base, int exponent) {
    if (exponent == 0) {
        return "1";
    }
    if (exponent == 1) {
        return base;
    }

    std::string result = "1";
    std::string current_base = base;
    while (exponent > 0) {
        if (exponent & 1) {
            result = multiply(result, current_base);
        }
        current_base = multiply(current_base, current_base);
        exponent >>= 1;
    }

    return result;
}

int main() {
    std::string base = "2";
    int exponent = 1023;
    std::string result = power(base, exponent);
    std::string s=std::to_string(std::pow(2,1023)).substr(0,result.length());
    std::cout << "2 ^ 1023 = " << result << std::endl;
    if(result!=s)
    {
        std::cout << "Error: The result is incorrect." << std::endl;
    }else
        std::cout<<"Correct"<<std::endl;
    return 0;
}